<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" id="f1">
    <button id = "btn">upload</button>
</body>
<script>
    let btn = document.getElementById("btn");
    let f1 = document.getElementById("f1");
    btn.onclick = () => {
        console.log(f1.files);
        if(f1.files.length > 0) {
            let fileObj = f1.files[0];
            //FormData的用法
            let formData = new FormData();
            formData.append("image", fileObj);
            formData.append("name" , "tsh");
            fetch("http://192.168.42.166:3000/upload" , {method: "POST" , body: formData})
                .then(res => res.json()) 
                .then(res => {
                    console.log(res);
                })
        }
    }
</script>
</html>